<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css}" type="text/css">
    <link th:href="@{/erp/Widget/icheck/icheck.css}" rel="stylesheet" type="text/css"/>
    <!--[if IE 7]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome-ie7.min.css}"/>
    <![endif]-->
    <!--[if lte IE 8]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace-ie.min.css}"/>
    <![endif]-->
    <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
    <!-- page specific plugin scripts -->
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/laydate/laydate.js}" type="text/javascript"></script>
    <script type="text/javascript" th:src="@{/erp/Widget/zTree/js/jquery.ztree.all-3.5.min.js}"></script>
    <script th:src="@{/erp/js/lrtk.js}" type="text/javascript"></script>
    <title>车辆驾驶员</title>
</head>
<body>
<div class=" page-content clearfix">
    <div id="products_style">
        <div class="search_style">
            <form>
                <ul class="search_content clearfix">
                    <li><label class="l_f">驾驶员名称</label><input name="drivername" type="text" class="text_add"
                                                               placeholder="驾驶员名称" style=" width:250px"/></li>
                    <li><label class="l_f">驾驶证号</label><input name="driverlicense" type="text" class="text_add"
                                                              placeholder="驾驶员名称" style=" width:250px"/></li>
                    <li style="width:90px;">
                        <button type="button" id="selectbyname" class="btn_search"><i class="icon-search"></i>查询
                        </button>
                    </li>
                </ul>
            </form>
        </div>
        <div class="border clearfix">
       <span class="l_f">
        <!--<a href="good-add.html" title="添加商品" class="btn btn-warning Order_form"><i class="icon-plus"></i>添加商品</a>-->
        <button id="logistic_add" class="btn btn-warning"><i class="icon-plus"></i>添加驾驶员</button>
       </span>

        </div>

        <table class="table table-striped table-bordered table-hover" id="sample-table">
            <thead>
            <tr>
                <th style='display:none' width="150px">驾驶员ID</th>
                <th width="150px">驾驶员编号</th>
                <th width="80px">驾驶员姓名</th>
                <th width="120px">驾驶证号</th>
                <th width="190px">身份证号</th>
                <th width="150px">性别</th>
                <th width="100px">联系方式</th>
                <th style='display:none' width="150px">所属物流公司ID</th>
                <th width="150px">所属物流公司</th>
                <th width="100px">工龄(年)</th>


                <th width="150px">操作</th>
            </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
    </div>
</div>
</div>
</div>
<!--添加车辆图层-->
<div class="add_menber" id="add_menber_style" style="display:none">

    <ul class=" page-content">
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*人员姓名：</label>
            <div class="formControls ">
                <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="driverName"
                       name="驾驶员姓名">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*身份证号：</label>
            <div class="formControls ">
                <input type="text" onchange="isCardNo(this)" class="input-text" value="" placeholder="" id="idCard"
                       name="身份证号">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*驾驶证号：</label>
            <div class="formControls ">
                <input type="text" onchange="drivenum(this)" class="input-text" value="" placeholder=""
                       id="driverLicense" name="驾驶证号">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*联系方式：</label>
            <div class="formControls ">
                <input type="text" onchange="phone(this)" class="input-text" value="" placeholder="" id="driverControl"
                       name="联系方式">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*物流公司：&nbsp;</label>
            <div class="formControls ">
                <select class="select" id="logisticsName" style="margin-left:10px">
                    <option value="1">请选择</option>
                </select>
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*性别：&nbsp;</label>
            <div class="formControls ">
                <select class="select" id="driverSex" style="margin-left:10px">
                    <option value="男">男</option>
                    <option value="女">女</option>
                </select>
            </div>
        </div>


        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>*工作年限：</label>
            <div class="formControls ">
                <input type="text" onchange="zzs(this)" id="driverAge" class="input-text" value="" placeholder=""
                       name="工作年限">
            </div>
        </div>

        <div class="Operate_cont clearfix">
            <label class="form-label">*备注：</label>
            <div class="formControls">
                <textarea name="" rows="" id="remarks" class="textarea" maxlength="120" placeholder="说点什么...最少输入10个字符"
                          datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！"></textarea>

            </div>
        </div>
        <div class=""/>
        <div class="" style=" text-align:center"/>
    </ul>
</div>

</div>
</div>
</div>
</div>
</div>
<!--编辑属性图层-->
<div class="edit_menber" id="edit_menber_style" style="display:none">

    <div class="Operate_cont clearfix">
        <label class="form-label"><span class="c-red"></span>人员姓名：</label>
        <div class="formControls ">
            <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="driverNamebj"
                   name="驾驶员姓名">
        </div>
    </div>
    <div class="Operate_cont clearfix">
        <label class="form-label"><span class="c-red"></span>驾驶证号：</label>
        <div class="formControls ">
            <input type="text" onchange="drivenum(this)" class="input-text" value="0000001" placeholder=""
                   id="driverLicensebj" name="驾驶证号">
        </div>
    </div>
    <div class="Operate_cont clearfix">
        <label class="form-label"><span class="c-red"></span>身份证号：</label>
        <div class="formControls ">
            <input type="text" onchange="isCardNo(this)" class="input-text" value="4127261879456688" placeholder=""
                   id="idCardbj" name="身份证号">
        </div>
    </div>
    <div class="Operate_cont clearfix">
        <label class="form-label"><span class="c-red"></span>联系方式：</label>
        <div class="formControls ">
            <input type="text" onchange="phone(this)" class="input-text" value="4127261879456688" placeholder=""
                   id="driverControlbj" name="联系方式">
        </div>
    </div>


    <div class="Operate_cont clearfix">
        <label class="form-label"><span class="c-red"></span>物流公司：&nbsp;</label>
        <div class="formControls ">
            <select class="select" id="logisticsNamebj" style="margin-left:10px">
                <option>请选择</option>

            </select>
        </div>
    </div>

    <div class="Operate_cont clearfix">
        <label class="form-label"><span class="c-red"></span>性别：&nbsp;</label>
        <div class="formControls ">
            <select class="select" id="driverSexbj" style="margin-left:10px">
                <option>请选择</option>
                <option value="男" id="nan">男</option>
                <option value="女" id="nv">女</option>
            </select>
        </div>
    </div>

    <div class="Operate_cont clearfix">
        <label class="form-label"><span class="c-red"></span>工作年限：</label>
        <div class="formControls ">
            <input type="text" onchange="zzs(this)" class="input-text" value="10年" placeholder="" id="driverAgebj"
                   name="工作年限">
        </div>
    </div>

    <div class="Operate_cont clearfix">
        <label class="form-label">备注：</label>
        <div class="formControls">
            <textarea name="" rows="" id="remarksbj" maxlength="120" class="textarea" placeholder="说点什么...最少输入10个字符"
                      datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！">老司机老司机老司机老司机老司机老司机老司机</textarea>

        </div>
    </div>
    <div class="">
        <div class="" style=" text-align:center">
        </div>

    </div>
</div>
</div>
</div>

</div>


</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" th:src="@{/js/regularExpression.js}"></script>
<script type="text/javascript" th:src="@{/js/l_v.js}"></script>
</body>
</html>
<script>
    /*物流公司-添加*/
    $('#logistic_add').on('click', function () {


        layer.open({
            type: 1,
            title: '添加驾驶员',
            maxmin: true,
            shadeClose: true, //点击遮罩关闭层
            area: ['600px', ''],
            content: $('#add_menber_style'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $(".add_menber input[type$='text']").each(function (n) {
                    if ($(this).val() == "") {

                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                                title: '提示框',
                                icon: 0,
                            }
                        );
                        num++;
                        return false;
                    }

                });
                if ($('#logisticsName').val() == "1") {

                    layer.alert( "物流公司不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        }
                    );
                    num++;
                    return false;
                }
                if (num > 0) {
                    return false;
                } else {

                    $.ajax({
                        data: {
                            "driverName": document.getElementById('driverName').value
                            , "idCard": document.getElementById('idCard').value
                            , "driverLicense": document.getElementById('driverLicense').value
                            , "driverControl": document.getElementById('driverControl').value
                            , "logisticsId": document.getElementById('logisticsName').value
                            , "driverSex": document.getElementById('driverSex').value
                            , "driverAge": document.getElementById('driverAge').value
                            , "remarks": document.getElementById('remarks').value
                        },
                        type: 'post',
                        dataType: 'josn',
                        url: '/driver/adddriver',
                        success: function (data) {
                            alert(data);
                            if(!data.rs){
                                layer.msg(data.msg,{icon:2,time:2000})
                            }
                        }
                    });


                    layer.alert('添加成功！', {
                        title: '提示框',
                        icon: 1,
                    });
                    layer.close(index);
                    window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
                }
            }
        });
    });

    /*物流公司信息-编辑*/
    function member_edit(e) {

        var id = $(e).parent().parent().children("td:eq(0)").text();
        var logisticsid = $(e).parent().parent().children("td:eq(7)").text();
        var sex = $(e).parent().parent().children("td:eq(5)").text();
        document.getElementById('driverNamebj').value = $(e).parent().parent().children("td:eq(2)").text();
        document.getElementById('driverLicensebj').value = $(e).parent().parent().children("td:eq(3)").text();
        document.getElementById('driverControlbj').value = $(e).parent().parent().children("td:eq(6)").text();
        document.getElementById('idCardbj').value = $(e).parent().parent().children("td:eq(4)").text();
        document.getElementById('driverAgebj').value = $(e).parent().parent().children("td:eq(11)").text();

        $.ajax({
            url: '[[@{/logisticsxx/alllogistics}]]',
            success: function (data) {
                console.log(data);
                if(data.rs) {
                    var d=data.data;
                    for (var i in d) {
                        if (logisticsid == d[i].logisticsId) {
                            $('#logisticsnamebj:last').append("<option selected = \"selected\" value=" + d[i].logisticsId + ">   " + d[i].logisticsName + "</option>")
                        } else {
                            $('#logisticsnamebj:last').append("<option value=" + d[i].logisticsId + ">" + d[i].logisticsName + "</option>")
                        }
                    }
                }else {
                    layer.msg(data.msg,{icon:2,time:2000});
                }
            }

        })


        console.log(sex);
        if (sex == "男") {
            $('#nan').prop('selected', 'true')
        } else {
            $('#nv').prop('selected', 'true')
        }


        $.ajax({
            url: '[[@{/driver/findremarks}]]',
            data: {
                "id": id
            },
            success: function (data) {
                console.log(data);
                if(data.rs){
                    var d=data.data;
                    document.getElementById('remarksbj').value = d;
                }else {
                    layer.msg(data.msg,{icon:2,time:2000})
                }

            }

        })


        layer.open({
            type: 1,
            title: '修改驾驶员信息',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['600px', ''],
            content: $('#edit_menber_style'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $(".edit_menber input[type$='text']").each(function (n) {
                    if ($(this).val() == "") {

                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        });
                        num++;
                        return false;
                    }
                });
                if ($('#logisticsNamebj').val() == "") {

                    layer.alert( "物流公司不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        }
                    );
                    num++;
                    return false;
                }
                if (num > 0) {
                    return false;
                } else {

                    $.ajax({
                        data: {
                            "driverId": id
                            , "driverName": document.getElementById('driverNamebj').value
                            , "driverLicense": document.getElementById('driverLicensebj').value
                            , "idCard": document.getElementById('idCardbj').value
                            , "driverControlbj": document.getElementById('driverControlbj').value
                            , "logisticsId": document.getElementById('logisticsNamebj').value
                            , "driverSex": document.getElementById('driverSexbj').value
                            , "driverAge": document.getElementById('driverAgebj').value
                            , "remarks": document.getElementById('remarksbj').value
                        },
                        type: 'post',
                        dataType: 'josn',
                        url: '/driver/updatedriver',
                        success: function (data) {
                            alert(data);
                            if(!data.rs){
                                layer.msg(data.msg,{icon:2,time:2000})
                            }
                        }
                    });


                    layer.alert('修改成功！', {
                        title: '提示框',
                        icon: 1,
                    });
                    layer.close(index);
                    window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
                }


            }
        });
    }

    jQuery(function ($) {


        var oTable1 = $('#sample-table').dataTable({
            searching: false,
            serverSide: true,
            ajax: {
                url: '/driver/findAll',
                type: 'post',
                data: function (d) {
                    var data = $('form').serialize();
                    var searchParame = {
                        start: d.start,
                        length: d.length,
                    };
                    data = data + '&' + $.param(searchParame);
                    return data;
                }
            },

            columns: [
                {"data": "driverId", "className": "hidden"},
                {
                    "data": "driverId", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append(row + 1)
                    }
                },
                {"data": "driverName"},
                {"data": "driverLicense"},
                {"data": "idCard"},
                {"data": "driverSex"},
                {"data": "driverControl"},
                {"data": "logisticsId", "className": "hidden"},
                {"data": "logisticsName"},
                {"data": "driverAge"},
                {
                    "data": "logisticsId", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append(' <a title="编辑" onclick="member_edit(this)" href="javascript:;"  class="btn btn-xs btn-info" ><i class="icon-edit bigger-120"></i></a> \n' +

                            '                    <a title="删除" href="javascript:;"  onclick="member_del(this,\'1\')" \n' +
                            'class="btn btn-xs btn-warning" ><i class="icon-trash bigger-120"></i></a>')
                    }
                },

            ]
        })

        /*搜索*/
        $('#selectbyname').click(function () {
            oTable1.fnUpdate();
        })


    });


</script>
<script type="text/javascript">


    /*产品-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            var ids = $(obj).parent().parent().children("td:eq(0)").text();
            console.log(ids);
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {"id": ids},
                url: '/driver/detelevehicle',
                success: function (data) {
                    alert(data);
                    if(!data.rs){
                        layer.msg(data.msg,{icon:2,time:2000})
                    }
                }
            })

            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
            window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
        });
    }

</script>
